package com.it.springbootspringdatajpa.service.impl;

import com.it.springbootspringdatajpa.dao.ContractRepository;
import com.it.springbootspringdatajpa.domain.Contract;
import com.it.springbootspringdatajpa.service.IContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @projectName: springboot-spring-data-jpa
 * @package: com.it.springbootspringdatajpa.service.impl
 * @className: ContractServiceImpl
 * @author: Navid
 * @description: TODO
 * @date: 2021/10/23 18:37
 * @version: 1.0
 */
@Service
public class ContractServiceImpl implements IContractService {

    @Autowired
    ContractRepository repository;

    @Override
    public List<Contract> findAll() {
        return repository.findAll();
    }

    @Override
    public void insert(Contract contract) {
        repository.save(contract);
        System.out.println("insert");
    }

    @Override
    @Transactional(rollbackOn = Exception.class)
    public void updateNameById(String name, Integer id) {
        repository.updateNameById(name, id);
        System.out.println("updateNameById: " + name + " " + id);
    }

    @Override
    @Transactional(rollbackOn = Exception.class)
    public void deleteById(Integer id) {
        repository.deleteById(id);
        System.out.println("deleteById:" + id);
    }

    @Override
    public Contract findByCondition(String contractNo, String contractType, String contactName) {
        return repository.findByCondition(contractNo, contractType, contactName);
    }

    @Override
    public List<Contract> findByContractStatus(boolean contractStatus) {
        return repository.findByContractStatus(contractStatus);
    }

    @Override
    public List<Contract> findByPaged(int pageIndex, int pageSize, String contractNo) {
        return repository.findByPage(pageIndex, pageSize, contractNo);
    }


}
